package org.fuys.coder.common.config.sys;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import org.springframework.web.filter.CorsFilter;

import java.util.Arrays;

/**
 * @projectName: fuys-low-coder
 * @package: org.fuys.coder.common.config.sys
 * @className: CorConfig
 * @author: WangJing
 * @description: 跨域问题
 * @date: 2024/6/21 17:12
 * @version: 1.0
 */
public class CorConfig {

    public CorsFilter corsFilter(){
        UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
        CorsConfiguration configuration=new CorsConfiguration();

        configuration.setAllowedOrigins(Arrays.asList("http://localhost:8081","http://127.0.0.1:8081"));
        configuration.addAllowedHeader("*");
        configuration.addAllowedOrigin("*");
        configuration.addAllowedMethod("*");
        source.registerCorsConfiguration("/**",configuration);
        return new CorsFilter(source);
    }
}
